home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.UserControl ctlSolitaire
- BackColor = &H00C0FFFF&
- ClientHeight = 7155
- ClientLeft = 0
- ClientTop = 0
- ClientWidth = 7200
- ScaleHeight = 477
- ScaleMode = 3 'Pixel
- ScaleWidth = 480
- Begin VB.CommandButton cmdRedo
- Caption = "Redo"
- Height = 495
- Left = 840
- TabIndex = 3
- Top = 6480
- Width = 615
- End
- Begin VB.CommandButton cmdUndo
- Caption = "Undo"
- Height = 495
- Left = 120
- TabIndex = 2
- Top = 6480
- Width = 615
- End
- Begin VB.CommandButton cmdNewGame
- Caption = "New Game"
- Height = 495
- Left = 5760
- TabIndex = 1
- Top = 6480
- Width = 1215
- End
- Begin VB.Shape shpBorder
- BorderColor = &H00FF0000&
- BorderWidth = 2
- FillColor = &H00FF0000&
- Height = 495
- Left = 2280
- Shape = 3 'Circle
- Top = 360
- Width = 615
- End
- Begin VB.Image imgHole
- Height = 480
- Index = 0
- Left = 360
- Picture = "ctlSolitaire.ctx":0000
- Top = 360
- Width = 480
- Visible = 0 'False
- End
- Begin VB.Label lblMarblesLeft
- Alignment = 2 'Center
- BackStyle = 0 'Transparent
- Caption = "32"
- Enabled = 0 'False
- Height = 255
- Left = 1920
- TabIndex = 0
- Top = 480
- Width = 255
- End
- Begin VB.Image imgMarble
- DragMode = 1 'Automatic
- Height = 480
- Index = 0
- Left = 1080
- Picture = "ctlSolitaire.ctx":030A
- Top = 360
- Width = 480
- End
- Attribute VB_Name = "ctlSolitaire"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = True
- '-------------------------------------------------------------------------
- 'Author: Anders Fransson
- 'Email: anders.fransson@enator.se
- 'Internet: http://hem1.passagen.se/fylke
- 'Date: 97-12-10
- '-------------------------------------------------------------------------
- Option Explicit
- Private m_iDragIndex As Integer
- Private m_iMarblesLeft As Integer
- Private m_iOldMovesIndex As Integer
- Private m_vOldMoves(1 To 2, 1 To 35) As Integer
- Private Const SIZE As Integer = 7
- Private Const HOLE_WIDTH As Integer = 50
- Private Const BORDER_TOP As Integer = 17
- Private Const BORDER_LEFT As Integer = 17
- Private Const BORDER_DIAMETER As Integer = 445
- Private Sub cmdNewGame_Click()
- NewGame
- End Sub
- Private Sub cmdRedo_Click()
- Redo
- End Sub
- Private Sub cmdUndo_Click()
- Undo
- End Sub
- Private Sub imgHole_MouseDown(Index As Integer, Button As Integer, _
- Shift As Integer, X As Single, Y As Single)
- 'Undo or redo move if Shift or Ctrl
- If Shift = 1 Then Redo
- If Shift = 2 Then Undo
- End Sub
- Private Sub UserControl_DragDrop(Source As Control, X As Single, Y As Single)
- m_iDragIndex = 0
- Source.Visible = True
- End Sub
- Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
- 'Undo or redo move if Shift or Ctrl
- If Shift = 1 Then Redo
- If Shift = 2 Then Undo
- End Sub
- Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- 'Show last draged marble if it has been dropped outside form
- If Not m_iDragIndex = 0 Then imgMarble(m_iDragIndex).Visible = True
- End Sub
- Private Sub imgMarble_DragDrop(Index As Integer, Source As Control, _
- X As Single, Y As Single)
- m_iDragIndex = 0
- Source.Visible = True
- End Sub
- Private Sub imgMarble_DragOver(Index As Integer, Source As Control, _
- X As Single, Y As Single, State As Integer)
- Source.Visible = False
- m_iDragIndex = Source.Index
- End Sub
- Private Static Sub imgHole_DragDrop(Index As Integer, Source As Control, _
- X As Single, Y As Single)
- Dim xHole%, yHole%, xSource%, ySource%
- 'Calculate coordinates for source-marble and drop-hole
- xHole = (Index) Mod SIZE
- yHole = (Index) \ SIZE
- xSource = Source.Index Mod SIZE
- ySource = Source.Index \ SIZE
- m_iDragIndex = 0
- 'Show source-marble and exit sub if move isn't valid
- If Not ((Abs(yHole - ySource) = 2 And (xHole = xSource)) Or _
- (Abs(xHole - xSource) = 2 And (yHole = ySource))) Then
- Source.Visible = True
- Exit Sub
- End If
- PlaySound App.Path & "\Drop.wav"
- 'Show source-marble and exit sub if move isn't valid
- If Not imgMarble((Index + Source.Index) / 2).Visible Then
- Source.Visible = True
- Exit Sub
- End If
- lblMarblesLeft.Move imgMarble((Index + Source.Index) / 2).Left + 7, _
- imgMarble((Index + Source.Index) / 2).Top + 9
- 'Update move-menus
- cmdUndo.Enabled = True
- cmdRedo.Enabled = False
- 'Update the old-moves variable
- m_iOldMovesIndex = m_iOldMovesIndex + 1
- m_vOldMoves(1, m_iOldMovesIndex) = Source.Index
- m_vOldMoves(2, m_iOldMovesIndex) = Index
- m_vOldMoves(1, m_iOldMovesIndex + 1) = 0
- m_vOldMoves(2, m_iOldMovesIndex + 1) = 0
- 'Hide and show involved marbles
- Source.Visible = False
- imgMarble((Index + Source.Index) / 2).Visible = False
- imgMarble(Index).Visible = True
- 'Update form caption
- m_iMarblesLeft = m_iMarblesLeft - 1
- lblMarblesLeft = m_iMarblesLeft
- End Sub
- Private Static Sub NewGame()
- Dim i%, j%
- 'Show marbles
- For i = 0 To SIZE - 1: For j = 0 To SIZE - 1
- If Not ((i < 2 And (j < 2 Or j > 4)) Or (i > 4 And (j < 2 Or j > 4))) Then _
- imgMarble(i * SIZE + j).Visible = True
- If (i = 3 And j = 3) Then imgMarble(i * SIZE + j).Visible = False
- Next j: Next i
- 'Reset old-moves
- For i = 1 To 2
- For j = LBound(m_vOldMoves, 1) To UBound(m_vOldMoves, 1)
- m_vOldMoves(i, j) = 0
- Next j
- Next i
- 'Start values
- m_iDragIndex = 0
- m_iOldMovesIndex = 0
- m_iMarblesLeft = 32
- cmdUndo.Enabled = False
- cmdRedo.Enabled = False
- lblMarblesLeft = m_iMarblesLeft
- lblMarblesLeft.Move 231, 233
- End Sub
- Private Sub Undo()
- 'Exit if Undo-menu is disabled
- If Not cmdUndo.Enabled Then Exit Sub
- PlaySound App.Path & "\Drop.wav"
- 'Update form caption
- m_iMarblesLeft = m_iMarblesLeft + 1
- lblMarblesLeft = m_iMarblesLeft
- 'Update marbles visability and old-moves
- imgMarble(m_vOldMoves(1, m_iOldMovesIndex)).Visible = True
- imgMarble((m_vOldMoves(1, m_iOldMovesIndex) + _
- m_vOldMoves(2, m_iOldMovesIndex)) / 2).Visible = True
- 'Plave label with marbles left
- lblMarblesLeft.Move imgMarble(m_vOldMoves(2, m_iOldMovesIndex)).Left + 7, _
- imgMarble(m_vOldMoves(2, m_iOldMovesIndex)).Top + 9
- imgMarble(m_vOldMoves(2, m_iOldMovesIndex)).Visible = False
- m_iOldMovesIndex = m_iOldMovesIndex - 1
- 'Disable Undo-menu if there is no more move to undo
- If m_iOldMovesIndex = 0 Then cmdUndo.Enabled = False
-
- 'Redo is now possible
- cmdRedo.Enabled = True
- End Sub
- Private Sub Redo()
- 'Exit if Redo-menu is disabled
- If Not cmdRedo.Enabled Then Exit Sub
- PlaySound App.Path & "\Drop.wav"
- 'Update form caption
- m_iMarblesLeft = m_iMarblesLeft - 1
- lblMarblesLeft = m_iMarblesLeft
- 'Update old-moves and marbles visability
- m_iOldMovesIndex = m_iOldMovesIndex + 1
- imgMarble(m_vOldMoves(1, m_iOldMovesIndex)).Visible = False
- imgMarble((m_vOldMoves(1, m_iOldMovesIndex) + _
- m_vOldMoves(2, m_iOldMovesIndex)) / 2).Visible = False
- imgMarble(m_vOldMoves(2, m_iOldMovesIndex)).Visible = True
- 'Plave label with marbles left
- lblMarblesLeft.Move imgMarble((m_vOldMoves(1, m_iOldMovesIndex) + _
- m_vOldMoves(2, m_iOldMovesIndex)) / 2).Left + 7, _
- imgMarble((m_vOldMoves(1, m_iOldMovesIndex) + _
- m_vOldMoves(2, m_iOldMovesIndex)) / 2).Top + 9
- 'Disable Redo-menu if there is no more move to redo
- If m_vOldMoves(1, m_iOldMovesIndex + 1) = 0 Then cmdRedo.Enabled = False
- 'Undo is now possible
- cmdUndo.Enabled = True
- End Sub
- Private Sub UserControl_Initialize()
- Dim i%, j%
- 'Place border
- shpBorder.Move BORDER_LEFT, BORDER_TOP, BORDER_DIAMETER, BORDER_DIAMETER
- 'Load and place images
- imgMarble(0).Visible = False
- imgMarble(0).DragIcon = imgMarble(0).Picture
- For i = 0 To SIZE - 1: For j = 0 To SIZE - 1
- If Not ((i < 2 And (j < 2 Or j > 4)) Or (i > 4 And (j < 2 Or j > 4))) Then
- Load imgMarble(i * SIZE + j)
- Load imgHole(i * SIZE + j)
- imgMarble(i * SIZE + j).Move 74 + HOLE_WIDTH * j, _
- 75 + HOLE_WIDTH * i
- imgHole(i * SIZE + j).Move 74 + HOLE_WIDTH * j, _
- 75 + HOLE_WIDTH * i
- imgHole(i * SIZE + j).Visible = True
- End If
- Next j: Next i
-
- NewGame
- End Sub
- Private Sub PlaySound(strSound As String)
- Dim wFlags%
- wFlags% = SND_ASYNC Or SND_NODEFAULT
- sndPlaySound strSound, wFlags%
- End Sub
-